/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef NODE_UTIL_INIFILE_H_
#define NODE_UTIL_INIFILE_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <string>
#include <vector>
#include "node/node.h"

namespace node {
    namespace util {

        class IniFile
        {
        public:
            IniFile(void);
            ~IniFile(void);

            bool open(const char *filename);

            const char *getString(const char *section, const char *key, const char *default = NULL);
            int getInt(const char *section, const char *key, int default = 0);
            long getLong(const char *section, const char *key, long default = 0L);
            double getDouble(const char *section, const char *key, double default = 0.0);

        private:
            bool parseLine(::std::string &line);

            struct KVPair {
                ::std::string key;
                ::std::string value;
            };
            struct Section {
                ::std::string name;
                ::std::vector<KVPair> data;
            };

            ::std::vector<struct Section> ini_;
            int lastest_section_;
            DISALLOW_COPY_AND_ASSIGN(IniFile);
        };

    }
}

#endif // NODE_UTIL_INIFILE_H_
